<template>
  <div class="box">
    <div class="head-fixed">
      <div class="head">
        <img src="../assets/zjt.png" alt="" class="back" @click="back()"/>
        <div>
          <img src="../assets/shoucang.png" alt="" v-show="store===false" @click="storeOn(0)"/>
          <img src="../assets/shoucang_1.png" alt="" v-show="store===true" @click="storeOn(1)" />
          <img src="../assets/jubao.png" alt="" @click="report()" />
          <img src="../assets/fenxiang.png" alt="" />
        </div>
      </div>
    </div>
    <div class="content">
      <div class="con-top">
        <div>
          <p>{{company.companyName}}</p>
          <span>{{company.scale}}人&nbsp;&nbsp;{{company.industry}}</span>
        </div>
        <div>
          <img src="../assets/avatar.png" alt="" />
        </div>
      </div>
      <div class="con-title">
        <p>公司地址</p>
        <span>{{company.address}}</span>
        <div class="firm-add">
          <img src="../assets/ditu.jpg" alt="">
        </div>
      </div>
      <div class="con-title1">
          <p>公司职位</p>
          <div class="block" v-for="item in list" @click="goDtl()">
            <div class="block-top">
              <span>{{ item.title }}</span>
              <span>{{ item.salaryRange }}</span>
            </div>
            <div class="block-class">
              <span>{{ item.workYearRange }}</span>
              <span>{{ item.eduBgdRange }}</span>
            </div>
            <div class="block-btn">
              <span>{{ item.companyName }}</span>
              <span>{{ item.regionName }}</span>
            </div>
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import { MessageBox,Toast  } from 'mint-ui';
export default {
  inject: ["reload"],
  name: "firm",
  components: {MessageBox,Toast },
  created() {
    // created 在模板渲染成html前调用，即通常初始化某些属性值，然后再渲染成视图
    this.companyId === this.init(this.companyId);
  },
  mounted() {
    // mounted在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作
  },
  // data() 为变量赋值等
  data() {
    return {
      status:localStorage.status,
      companyId:this.$route.params.companyId,
      company:[],
      list: [
        {
          job: "java开发",
          company: "大连华企智源有限公司",
          pay: "3-5K",
          city: "大连市",
          rqstd: [{ name: "1-3年" }, { name: "本科" }, { name: "技能" }],
        },
        {
          job: "java开发",
          company: "大连华企智源有限公司",
          pay: "3-5K",
          city: "大连市",
          rqstd: [{ name: "1-3年" }, { name: "本科" }, { name: "技能" }],
        },
      ],
      store:false
    };
  },
  // methods 编写js函数
  methods: {
	  //个人收藏公司
	  collect(){
	  	//获取登录账户id 后台获取
	  	this.$http({
	  	  method: "get",
	  	  url: 'api/ycusercollectjob/save',
	  	  params: {
			userId: localStorage.getItem("userId"),
	  		collectId: this.company.id,
	  		collectType: 0
	  	  },
	  	})
	  	.then(({data}) => {
	  	  console.log(data);
	  	})
	  },
	  //个人取消收藏公司
	  cancelCollect(){
	  	//获取登录账户id 后台获取
	  	this.$http({
	  	  method: "get",
	  	  url: 'api/ycusercollectjob/cancleCollect',
	  	  params: {
			userId: localStorage.getItem("userId"),
	  		collectId: this.company.id,
	  		collectType: 0
	  	  },
	  	})
	  	.then(({data}) => {
	  	  console.log(data);
	  	})
	  },
    init(id){
      alert(id)
      this.$http({
        methods:"get",
        url:"api/company/info/"+id,
        params:{
        },
      }).then(({data}) => {
        console.log(data)
        this.company = data.ycCompany;
        this.list = data.recruitList;
      })
    },
    back(){
      this.$router.go(-1);//返回上一层
    },
    goDtl(){
      this.$router.push("/post")
    },
    storeOn(i){
      if(i==0){
        this.store=true;
				//个人收藏表添数据
				this.collect();
      }else if(i==1){
        MessageBox.confirm('确定要取消收藏该公司吗?').then(action => {
          this.store=false;
					//个人收藏表删除数据
					this.cancelCollect();
          }).catch((err)=>{
            console.log(err)
          });
      }
    },
    report() {
      MessageBox.confirm("确定要举报该公司吗?")
        .then((action) => {

          Toast("举报成功");
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
html,
body,
.tac,
.box,
.tab-left,
.tab-left .el-menu {
  height: 100%;
}

.box {
  width: 100%;
  background: #fff;
}
.head-fixed {
  width: 100%;
  height: 84px;
  position: fixed;
  z-index: 999;
}
.head {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  display: flex;
  background: #fff;
  justify-content: space-between;
  /* border-bottom: 1px solid #dfdfdf; */
  /* box-shadow: 2px 2px 5px  #c7c7c7; */
}
.head div {
  display: flex;
  width: 30%;
  justify-content: space-between;
}
.back {
  width: 14px;
  height: 14px;
}
.head div img {
  width: 20px;
  height: 20px;
}
.content {
  position: relative;
  top: 40px;
  width: 100%;
  box-sizing: border-box;
  padding: 0 10px 40px 10px;
}
.con-top {
  box-sizing: border-box;
  padding: 10px 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #dfdfdf;
}
.con-top img {
  width: 50px;
  height: 50px;
  border-radius: 10px;
}
.con-title1 p{
  font-size: 12px;
  padding-top: 10px;
  font-weight: 900;
}
.con-top p {
  font-size: 20px;
  font-weight: 900;
}
.con-top span {
  font-size: 12px;
}
.con-title {
  padding: 10px 0;
}
.con-title p {
  font-size: 12px;
  font-weight: 900;
}
.con-title span {
  font-size: 12px;
  display: inline-block;
  padding-bottom: 20px;
}
.con-title{border-bottom: 1px solid #dfdfdf;}
.block {
  width:100%;
  box-sizing: border-box;
  padding: 10px;
  background: #fff;
  margin-top: 10px;
  height: 90px;
  display: flex;
  flex-flow: column;
  justify-content: space-between;
  border-radius: 10px;
  box-shadow: 2px 2px 5px #c7c7c7;
}
.block .block-top {
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
}
.block-top span:first-child {
  color: #333;
  font-weight: 700;
}
.block-top span:last-child {
  color: #3e63a8;
}
.block-calss {
  width: 100%;
}
.block-class span {
  background: #f0f0f0;
  color: #757575;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  margin-right: 10px;
}
.block-company {
  font-size: 12px;
  color: #757575;
}
.block-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #757575;
}

.firm-add{
  width: 100%;
  height: 200px;
  border-radius: 10px;
  overflow: hidden;
}
.firm-add img{
  width: 100%;
  height: 100%;
}
</style>
